#pragma once
#include "aDataPartBase.h"
#include "PhysXheaders.h"

namespace _DATAPARTFACTORY_
{
	namespace _PHYSICS_
	{
		class PhysicsPartFactory;
	
	}
}
	

namespace _DATAPART_
{
	namespace _PHYSICS_
	{
		class PhysicsPart:
			public _FOGGE_::_GDB_::aDataPartBase
		{
			friend _DATAPARTFACTORY_::_PHYSICS_::PhysicsPartFactory;
			FoDeclareRTTI;
		public:
			PhysicsPart(void);
			~PhysicsPart(void);

			void AttachChild(PhysicsPart* ptrPhysicsPart,NxJoint *joint);

			NxJoint* DetachChild(PhysicsPart* ptrPhysicsPart);

			PhysicsPart* GetParent()
			{
				return m_ptrParent;
			}

			void SetParent(_FOGGE_::_GDB_::foDataObject* ptrDataObject);

			void UpdateVelocity(float elapsedtime);
			void UpdateAngularVelocity(float elapsedtime);
			void NotifyBecomeNewMaster(aDataPartBase* ptrOldMaster);

			virtual void Update(float elapsedtime);

			virtual void  ActivateDataPart();


			NxActor* m_ptrNxActor;

			NxVec3 m_vVelocity;
			_FOMATH::Rotator m_rAngularVelocity;

			NxMat33 m_matModelRotOrigine;
			

		protected:
			void CopyFrom(aDataPartBase* ptrSource);
			
			void UpdatePose();
	
		private:

			struct ChildInfo
			{
				PhysicsPart* ptrPhysicsPart;
				NxJoint *ptrJoint;
				NxMat34 localPose;
			};
			NXU::NxuPhysicsCollection* m_ptrCollection;

			std::list<ChildInfo> m_listChildInfo;

			
			int m_DefaultBodyFlag;

			PhysicsPart* m_ptrParent; 


	

		};
	}
}

namespace _DATAPARTFACTORY_
{
	namespace _PHYSICS_
	{
		class PhysicsPartFactory:
			public _FOGGE_::_GDB_::aDataPartFactoryBase,
			public NXU_userNotify

		{
		public:
			PhysicsPartFactory(void);
			~PhysicsPartFactory(void);

			static _FOGGE_::foString	g_BasePath;
			static NxPhysicsSDK*	g_ptrPhysicsSDK;
			static NxScene*	g_ptrScene;

			_FOGGE_::_GDB_::aDataPartBase* LoadPart(TiXmlNode* ptrNode);

			_FOGGE_::_GDB_::aDataPartBase* CreatePart();


		/**
			Physx user notify handlers
		*/
		//@{
			void	NXU_notifyActor(NxActor	*actor,	const	char *userProperties);
		//@}

		protected:
			_DATAPART_::_PHYSICS_::PhysicsPart* m_ptrCurrentLoadingPart;//*!< to use for referance when make a link between physic part and physx actor in the funtion NXU_NotifyActor//  
			
		};


		class DummyPhysicsPartFactory:
			public PhysicsPartFactory

		{
		public:
			DummyPhysicsPartFactory(void);
			~DummyPhysicsPartFactory(void);

			_FOGGE_::_GDB_::aDataPartBase* LoadPart(TiXmlNode* ptrNode);

		};
	}
}
	